package cn.t16.ms.feign.order;

import cn.t16.common.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class OrderController {
    @Resource
    private IOrderService orderService;

    @GetMapping("/orders/{id}")
    public Result get(@PathVariable Integer id) {
        Order order =  orderService.get(id);
        return Result.returnResult(200,"success", order);
    }

    @GetMapping("/orders")
    public Result getAll() {
        List<Order> orders = orderService.getAll();
        return Result.returnResult(200,"success", orders);
    }

    @GetMapping("/search")
    public List<Order> getByUserId(Integer userId) {
        List<Order> orders = orderService.findByUserId(userId);
//        return Result.returnResult(200,"success", orders);
        return orders;
    }


    @PostMapping("/orders")
    public Result add(@RequestBody Order order) {
        order =  orderService.add(order);
        return Result.returnResult(200,"success", order);
    }
}
